<?php
$this->load->view('header');

if (strlen($this->session->flashdata('Error')) > 0) {
    echo '<div class="alert alert-danger alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Error') . '</div>';
    $this->session->unset_userdata('Error');
} elseif (strlen($this->session->flashdata('Success')) > 0) {
    echo '<div class="alert alert-success alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Success') . '</div>';
    $this->session->unset_userdata('Success');
}
?>

<div id="loader" class="container">
	<div class="col-md-offset-1">			
		<div class="col-md-11">			
			<div class="col-md-6">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Master Job Position</b></h4>
				</div>
				<div class="panel-body well" id="tablecontent">
					<form method="post" id="master_job" action="#">
						<div class="col-sm-5"><label for="nama_jabatan" class="control-label">Job Position<span style="color:red;">*</span></label></div>
						<div class="col-sm-7">
							<select id="nama_jabatan" name="nama_jabatan" class="form-control input-sm required">                         
								<option value="0">-- select --</option>
							<?php
								if (!empty($nama_jabatan)) { 
									foreach($job_select as $job_select => $key)
									{ ?>
										<option value="<?php echo $key['JOB']; ?>"<?php echo (strtoupper($nama_jabatan) == strtoupper($key['JOB'])) ? 'selected' : ''; ?>><?php echo $key['JOB']; ?></option>									
									<?php
									}
								} else {
									foreach($job_select as $job_select => $key)
									{ ?>
										<option value="<?php echo $key['JOB']; ?>"><?php echo $key['JOB']; ?></option>									
									<?php
										//echo '<option value="'.$key['JOB'].'">'.$key['JOB'].'</option>';
									}		
								}
							?>
							</select>						
						</div>
						<div class="col-sm-5"><label for="status" class="control-label">Status<span style="color:red;">*</span></label></div>
						<div class="col-sm-7">
							<select id="status_name" name="status_name" class="form-control input-sm required">       
								<?php
								if (!empty($status_name)) {
								?>
									<option value="">-- select --</option>
									<option value="PERMANEN"<?php echo (strtoupper($status_name) == 'PERMANEN') ? 'selected' : ''; ?>>PERMANEN</option>
									<option value="KONTRAK"<?php echo (strtoupper($status_name) == 'KONTRAK') ? 'selected' : ''; ?>>KONTRAK</option>
								<?php 
								} else {
								?>
									<option value="">-- select --</option>
									<option value="PERMANEN">PERMANEN</option>
									<option value="KONTRAK">KONTRAK</option>													
								<?php
								}
								?>
							</select>						
						</div>
						<div class="col-sm-12" style="margin-top:2px;">&nbsp;</div>
						<div class="col-sm-4">
							<!--button type="reset" class="btn btn-default btn-block">Clear</button-->
						</div>
						<div class="col-sm-4"></div>
						<div class="col-sm-4">
							<button type="button" class="btn btn-primary btn-block" onclick="search_data1();">
							<!--span class="glyphicon glyphicon-search"></span--> Search</button>
						</div>
						<div style="margin-top:20px" class="col-sm-8"><label for="work_facility" class="control-label"><b class="caret"></b> Work Facility Request</label></div>
						<div class="col-md-12">
							<div class="table-responsive">
							<table class="table table-bordered table-condensed table-striped">
								<thead><tr>
									<th>No</th>
									<th>Name</th>
									<th>Status</th>
									<?php
										if (!empty($list_data1)) {
									?>
											<th>Action</th>
									<?php
										}
									?>
								</tr></thead>
								<tbody>
									<?php
										if (empty($list_data1) && (empty($nama_jabatan) || empty($status_name))) {
											?>
											<tr><td colspan="3" style="text-align:center">No Data Available</td></tr>
											<?php 
										} else if (!empty($list_data1)) {
											$no_urut = 0; 
											foreach ($list_data1 as $row) {
												$no_urut++;
											?>
												<tr>
													<td style="text-align:center;"><?php echo $no_urut; ?>.</td>
													<td style="text-align:left;"><?php echo $row['RI_NAME']; ?></td>
													<td>
														<select id="ri_status<?php echo $no_urut; ?>" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y"<?php echo (strtoupper($row['RI_STATUS']) == 'Y') ? 'selected' : ''; ?>>Active</option>
															<option value="N"<?php echo (strtoupper($row['RI_STATUS']) == 'N') ? 'selected' : ''; ?>>Not Active</option>															
														</select>								
													</td>
													<td>
													<a class="btn btn-sm btn-warning" href="#" onclick="edit_data1('<?php echo $row['RI_NAME']; ?>','<?php echo $no_urut; ?>');">
														<!--span class="glyphicon glyphicon-edit"></span--> Edit</a>
													<a class="btn btn-sm btn-danger" href="#" onclick="delete_data1('<?php echo $row['RI_NAME']; ?>');">
														<!--span class="glyphicon glyphicon-remove"></span--> Delete</a>
													</td>
												</tr>
											<?php 
											}											
											if (!empty($list_fasilitas_kerja_new)) { ?>
												<tr>
													<td style="text-align:center;"><?php echo $no_urut+1; ?>.</td>
													<td>
														<select id="work_awal1" class="form-control input-sm">                         
															<option value="0">-- select --</option>
														<?php 
															foreach($list_fasilitas_kerja_new as $key)
															{
																echo '<option value="'.$key['RI_NAME'].'">'.$key['RI_NAME'].'</option>';
															} 
														?>							
														</select>
													</td>
													<td>
														<select id="status_awal1" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y">Active</option>
															<option value="N">Not Active</option>															
														</select>
													</td>
													<td>
														<a class="btn btn-sm btn-success" href="#" onclick="add_data1();">
														<!--span class="glyphicon glyphicon-plus"></span--> Add</a>
													</td>																																					
												</tr>
											<?php
											}
										} else {
									?>
												<tr>
													<td style="text-align:center;">1.</td>
													<td>
														<select id="work_awal1" class="form-control input-sm">                         
															<option value="0">-- select --</option>
														<?php 
															foreach($list_fasilitas_kerja as $keysz)
															{
																echo '<option value="'.$keysz['RI_NAME'].'">'.$keysz['RI_NAME'].'</option>';
															} 
														?>							
														</select>
													</td>
													<td>
														<select id="status_awal1" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y">Active</option>
															<option value="N">Not Active</option>															
														</select>
													</td>
												</tr>
									<?php
										}
									?>
								</tbody>
							</table>
							</div>
						</div>
						<div style="margin-top:20px" class="col-sm-8"></div>
						<div class="col-sm-4">
							<?php
							if (empty($list_data1) && !empty($nama_jabatan)) {
							?>
								<button type="button" class="btn btn-success btn-block" onclick="add_data1();">
								<!--span class="glyphicon glyphicon-plus"></span--> Add New</button>
							<?php
							} else if (empty($list_data1) && empty($nama_jabatan)) {
							?>
								<button type="button" class="btn btn-default btn-block" >No Action</button>
							<?php
							} 
							?>
						</div>
						<div style="margin-top:20px" class="col-sm-8"><label for="room_facility" class="control-label"><b class="caret"></b> Room Facility Request</label></div>
						<div class="col-md-12">
							<div class="table-responsive">
							<table class="table table-bordered table-condensed table-striped">
								<thead><tr>
									<th>No</th>
									<th>Name</th>
									<th>Status</th>
									<?php
										if (!empty($list_data2)) {
									?>
											<th>Action</th>
									<?php
										}
									?>
								</tr></thead>
								<tbody>
									<?php
										if (empty($list_data2) && (empty($nama_jabatan) || empty($status_name))) {

											?>
											<tr><td colspan="3" style="text-align:center">No Data Available</td></tr>
											<?php
										} else if (!empty($list_data2)) {
											$no_urut2 = 0; 
											foreach ($list_data2 as $row2) {
												$no_urut2++;
											?>
												<tr>
													<td style="text-align:center;"><?php echo $no_urut2; ?>.</td>
													<td style="text-align:left;"><?php echo $row2['RI_NAME']; ?></td>
													<td>
														<select id="ri_status2<?php echo $no_urut2; ?>" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y"<?php echo (strtoupper($row2['RI_STATUS']) == 'Y') ? 'selected' : ''; ?>>Active</option>
															<option value="N"<?php echo (strtoupper($row2['RI_STATUS']) == 'N') ? 'selected' : ''; ?>>Not Active</option>															
														</select>
													</td>
													<td>
													<a class="btn btn-sm btn-warning" href="#" onclick="edit_data2('<?php echo $row2['RI_NAME']; ?>','<?php echo $no_urut2; ?>');">
														<!--span class="glyphicon glyphicon-edit"></span--> Edit</a>
													<a class="btn btn-sm btn-danger" href="#" onclick="delete_data2('<?php echo $row2['RI_NAME']; ?>');">
														<!--span class="glyphicon glyphicon-remove"></span--> Delete</a>
													</td>
												</tr>
											<?php 
											} //echo ($no_urut2);											 
											if (!empty($list_fasilitas_ruang_kerja_new)) { ?>
												<tr>
													<td style="text-align:center;"><?php echo $no_urut2+1; ?>.</td>
													<td>
														<select id="work2_awal" class="form-control input-sm">                         
															<option value="0">-- select --</option>
														<?php 
															foreach($list_fasilitas_ruang_kerja_new as $key)
															{
																echo '<option value="'.$key['RI_NAME'].'">'.$key['RI_NAME'].'</option>';
															} 
														?>							
														</select>
													</td>
													<td>
														<select id="status2_awal" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y">Active</option>
															<option value="N">Not Active</option>															
														</select>
													</td>
													<td>
														<a class="btn btn-sm btn-success" href="#" onclick="add_data2();">
														<!--span class="glyphicon glyphicon-plus"></span--> Add</a>
													</td>
												</tr>
											<?php
											}
										} else {
									?>
												<tr>
													<td style="text-align:center;">1.</td>
													<td>
														<select id="work2_awal" class="form-control input-sm">                         
															<option value="0">-- select --</option>
														<?php 
															foreach($list_fasilitas_ruang_kerja as $keys)
															{
																echo '<option value="'.$keys['RI_NAME'].'">'.$keys['RI_NAME'].'</option>';
															} 
														?>							
														</select>
													</td>
													<td>
														<select id="status2_awal" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y">Active</option>
															<option value="N">Not Active</option>															
														</select>
													</td>
												</tr>
									<?php
										}
									?>
									
								</tbody>
							</table>
							</div>
						</div>
						<div class="col-sm-8"></div>
						<div class="col-sm-4">
							<?php
							if (empty($list_data2) && !empty($nama_jabatan)) {
							?>
								<button type="button" class="btn btn-success btn-block" onclick="add_data2();">
								<!--span class="glyphicon glyphicon-plus"></span--> Add New</button>
							<?php
							} else if (empty($list_data2) && empty($nama_jabatan)) {
							?>
								<button type="button" class="btn btn-default btn-block" >No Action</button>
							<?php
							} 
							?>
						</div>
					</form>		
				</div>
			</div>
			<div class="col-md-6">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Master Room Setting</b></h4>
				</div>
				<div class="panel-body well" id="tablecontent2">
					<form method="post" id="master_room" action="#">
						<!--div class="form-group"-->
							<div class="col-sm-5"><label for="lantai" class="control-label">Floor<span style="color:red;">*</span></label></div>
							<div class="col-sm-7">
								<select id="floor_name" class="form-control input-sm required" onchange="javascript:getRoom()" />                         
									<option value="0">-- select --</option>									
								<?php
									if (!empty($floor_name)) { 
										foreach($floor_select as $floor_select => $key)
										{ ?>
											<option value="<?php echo $key['MST_FLOOR_DESC']; ?>"<?php echo ($floor_name == $key['MST_FLOOR_DESC']) ? 'selected' : ''; ?>><?php echo $key['MST_FLOOR_DESC']; ?></option>									
										<?php
										}
									} else {
										foreach($floor_select as $floor_select => $key)
										{ ?>
											<option value="<?php echo $key['MST_FLOOR_DESC']; ?>"><?php echo $key['MST_FLOOR_DESC']; ?></option>									
										<?php
										}		
									}
								?>															
								</select>						
							</div>
						<!--/div-->
						<!--div class="form-group"-->
							<div class="col-sm-5"><label for="kode_jabatan2" class="control-label">Job Position<span style="color:red;">*</span></label></div>
							<div class="col-sm-7">
								<select id="nama_jabatan2" class="form-control input-sm required">                         
									<option value="0">-- select --</option>
								<?php
									if (!empty($nama_jabatan2)) { 
										foreach($job_select2 as $job_select2 => $key)
										{ ?>
											<option value="<?php echo $key['JOB']; ?>"<?php echo (strtoupper($nama_jabatan2) == strtoupper($key['JOB'])) ? 'selected' : ''; ?>><?php echo $key['JOB']; ?></option>									
										<?php
										}
									} else {
										foreach($job_select2 as $job_select2 => $key)
										{ ?>
											<option value="<?php echo $key['JOB']; ?>"><?php echo $key['JOB']; ?></option>									
										<?php
										}		
									}
								?>
								</select>						
							</div>
						<!--/div-->
						<div class="form-group" id="ruang_select">
							<div class="col-sm-5"><label for="ruang" class="control-label">Room Name</label></div>
							<div class="col-sm-7">
								<select id="ruang_name" class="form-control input-sm">                         
									<?php
									if (!empty($ruang_name)) { ?>
										<option value="0">-- select --</option>
										<option value="<?php echo $ruang_name; ?>"<?php echo ($ruang_name == $ruang_name) ? 'selected' : ''; ?>><?php echo $ruang_name; ?></option>										
									<?php										
									} else {
									?>
										<option disabled="disabled" value="0">-- select floor first --</option>											
									<?php
									} ?>
								</select>												
							</div>													
							<div class="col-sm-5"><label align="right" for="l_new_room" class="control-label input-sm">New Name<span style="color:red;">*</span></label></div>						
							<div class="col-sm-7">
								<?php
								if (!empty($new_room)) { ?>
									<input type="text" class="form-control input-sm" id="new_room" value="<?php echo $new_room; ?>"> 
								<?php										
								} else {
								?>
									<input type="text" class="form-control input-sm" id="new_room" value=""> <!-- disabled="disabled" -->									
								<?php
								} ?>							
							</div>
						</div>
						<div class="col-sm-8">&nbsp;</div>
						<div class="col-sm-8" style="margin-top:2px;">&nbsp;</div>
						<div class="col-sm-4">
							<button type="button" class="btn btn-primary btn-block" onclick="search_data2();">
							<!--span class="glyphicon glyphicon-search"></span--> Search</button>
						</div>
						<div style="margin-top:20px" class="col-sm-8"><label for="room_facility2" class="control-label"><b class="caret"></b> All Facility Request</label></div>
						<div class="col-md-12">
							<div class="table-responsive">
							<table class="table table-bordered table-condensed table-striped">
								<thead><tr>
									<th>No</th>
									<th>Name</th>
									<?php
										if (!empty($list_data3) || !empty($list_data4)) {
									?>
											<th>Type</th>
									<?php
										}
									?>
									<th>Status</th>
									<?php
										if (!empty($list_data3) || !empty($list_data4)) {
									?>
											<th>Action</th>
									<?php
										}
									?>
								</tr></thead>
								<tbody>
									<?php
										if (empty($list_data3) && (empty($floor_name) || empty($nama_jabatan2))) {
											?>
											<tr><td colspan="4" style="text-align:center">No Data Available</td></tr>
											<?php
										} else if (!empty($list_data3) && empty($ruang_name)) {
											$no_urut = 0; 
											?>
											
											<?php 	
											foreach ($list_data3 as $row) {
												$no_urut++;
											?>
												<tr>
													<td style="text-align:center;"><?php echo $no_urut; ?>.</td>
													<td style="text-align:left;"><?php echo $row['RI_NAME']; ?></td>
													<td style="text-align:left;"><?php echo $row['RI_TYPE']; ?></td>
													<td>
														<select id="ri_status<?php echo $no_urut; ?>" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y"<?php echo (strtoupper($row['RI_STATUS']) == 'Y') ? 'selected' : ''; ?>>Active</option>
															<option value="N"<?php echo (strtoupper($row['RI_STATUS']) == 'N') ? 'selected' : ''; ?>>Not Active</option>															
														</select>								
													</td>
													<td>
													<a class="btn btn-sm btn-warning" href="#" onclick="edit_data3('<?php echo $row['RI_ID']; ?>','<?php echo $row['RI_TYPE']; ?>','<?php echo $no_urut; ?>');">
														<!--span class="glyphicon glyphicon-edit"></span--> Edit</a>
													<a class="btn btn-sm btn-danger" href="#" onclick="delete_data3('<?php echo $row['RBL_ID']; ?>','<?php echo $row['RI_NAME']; ?>');">
														<!--span class="glyphicon glyphicon-remove"></span--> Delete</a>
													</td>										
												</tr>
											<?php
											}
											
											if (!empty($list_fasilitas_request)) { ?>
												<tr>
													<td style="text-align:center;"><?php echo $no_urut+1; ?>.</td>
													<td>
														<select id="work_awal3" class="form-control input-sm">                         
															<option value="0">-- select--</option>
														<?php 
															foreach($list_fasilitas_request as $key)
															{
																echo '<option value="'.$key['RI_ID'].'">'.$key['RI_NAME'].'</option>';
															} 
														?>							
														</select>
													</td>
													<td></td>
													<td>
														<select id="status_awal3" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y">Active</option>
															<option value="N">Not Active</option>															
														</select>
													</td>
													
													<?php
													if (!empty($floor_name)) {
													?>
														<td>
															<a class="btn btn-sm btn-success" href="#" onclick="add_data3();">
															<!--span class="glyphicon glyphicon-plus"></span--> Add</a>
														</td>
													<?php
													}
													?>
													
												</tr>
											<?php
											} 	
											 
										} else if ((!empty($list_data3) || !empty($list_data4)) && !empty($ruang_name)) {
											$no_urut = 0; 
											?>
											
											<?php 	
											foreach ($list_data3 as $row) {
												$no_urut++;
											?>
												<tr>
													<td style="text-align:center;"><?php echo $no_urut; ?>.</td>
													<td style="text-align:left;"><?php echo $row['RI_NAME']; ?></td>
													<td style="text-align:left;"><?php echo $row['RI_TYPE']; ?></td>
													<td>
														<select id="ri_status<?php echo $no_urut; ?>" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y"<?php echo (strtoupper($row['RI_STATUS']) == 'Y') ? 'selected' : ''; ?>>Active</option>
															<option value="N"<?php echo (strtoupper($row['RI_STATUS']) == 'N') ? 'selected' : ''; ?>>Not Active</option>															
														</select>								
													</td>
													<td>
													<a class="btn btn-sm btn-warning" href="#" onclick="edit_data3('<?php echo $row['RI_ID']; ?>','<?php echo $row['RI_TYPE']; ?>','<?php echo $no_urut; ?>');">
														<!--span class="glyphicon glyphicon-edit"></span--> Edit</a>
													<a class="btn btn-sm btn-danger" href="#" onclick="delete_data3('<?php echo $row['RBL_ID']; ?>','<?php echo $row['RI_NAME']; ?>');">
														<!--span class="glyphicon glyphicon-remove"></span--> Delete</a>
													</td>
												</tr>
											<?php
											}
											
											foreach ($list_data4 as $row) {
												$no_urut++;
											?>
												<tr>
													<td style="text-align:center;"><?php echo $no_urut; ?>.</td>
													<td style="text-align:left;"><?php echo $row['RI_NAME']; ?></td>
													<td style="text-align:left;"><?php echo $row['RI_TYPE']; ?></td>
													<td>
														<?php
															// if(strtoupper($row['RI_STATUS']) == 'Y'){echo 'Active';} else {echo 'Not Active';}
														?>
														<select id="ri_status<?php echo $no_urut; ?>" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y"<?php echo (strtoupper($row['RI_STATUS']) == 'Y') ? 'selected' : ''; ?>>Active</option>
															<option value="N"<?php echo (strtoupper($row['RI_STATUS']) == 'N') ? 'selected' : ''; ?>>Not Active</option>															
														</select>								
													</td>
													<td>
													<a class="btn btn-sm btn-warning" href="#" onclick="edit_data3('<?php echo $row['RI_ID']; ?>','<?php echo $row['RI_TYPE']; ?>','<?php echo $no_urut; ?>');">
														<!--span class="glyphicon glyphicon-edit"></span--> Edit</a>
													<a class="btn btn-sm btn-danger" href="#" onclick="delete_data3('<?php echo $row['RBL_ID']; ?>','<?php echo $row['RI_NAME']; ?>');">
														<!--span class="glyphicon glyphicon-remove"></span--> Delete</a>
													</td>													
												</tr>
											<?php
											}
											
											if (!empty($list_fasilitas_request)) { ?>
												<tr>
													<td style="text-align:center;"><?php echo $no_urut+1; ?>.</td>
													<td>
														<select id="work_awal3" class="form-control input-sm">                         
															<option value="0">-- select--</option>
														<?php 
															foreach($list_fasilitas_request as $key)
															{
																echo '<option value="'.$key['RI_ID'].'">'.$key['RI_NAME'].'</option>';
															} 
														?>							
														</select>
													</td>
													<td></td>
													<td>
														<select id="status_awal3" class="form-control input-sm">                         
															<option value="">-- select --</option>
															<option value="Y">Active</option>
															<option value="N">Not Active</option>															
														</select>
													</td>
													
													<?php
													if (!empty($floor_name)) {
													?>
														<td>
															<a class="btn btn-sm btn-success" href="#" onclick="add_data3();">
															<!--span class="glyphicon glyphicon-plus"></span--> Add</a>
														</td>
													<?php
													}
													?>
													
												</tr>
											<?php
											} 
										
										} else {
									?>
											<tr>
												<td style="text-align:center;">1.</td>
												<td>
													<select id="work_awal3" class="form-control input-sm">                         
														<option value="0">-- select --</option>
													<?php 
														foreach($list_fasilitas_request as $keys)
														{
															echo '<option value="'.$keys['RI_ID'].'">'.$keys['RI_NAME'].'</option>';
														} 
													?>							
													</select>
												</td>
												<td>
													<select id="status_awal3" class="form-control input-sm">                         
														<option value="">-- select --</option>
														<option value="Y">Active</option>
														<option value="N">Not Active</option>															
													</select>
												</td>												
											</tr>
									<?php
										}
									?>
									
								</tbody>
							</table>
							</div>
						</div>
						<div class="col-sm-8"></div>
						<div class="col-sm-4">
							<?php
							if (empty($list_data3) && empty($list_data4) && !empty($floor_name)) {
							?>
								<button type="button" class="btn btn-success btn-block" onclick="add_data3();">
								<!--span class="glyphicon glyphicon-plus"></span--> Add New</button>
							<?php
							} else if (empty($list_data3) && empty($floor_name)) {
							?>
								<button type="button" class="btn btn-default btn-block" >No Action</button>
							<?php
							} 
							?>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<?php $this->load->view('footer'); ?>

<script type="text/javascript">
	function getRoom()
	{
		var floor_name = {floor_name:$("#floor_name").val()};
		$.ajax({
				type: "POST",
				url : "<?php echo site_url('setup/ShowRoomRequest');?>",
				data: floor_name,
				success: function(msg){$('#ruang_select').html(msg);}
			});
	};
	
	function search_data1() {
		$job   = $('#nama_jabatan').val();
		$status = $('#status_name').val();
	
		if ($job==="0"){$job="";}
		if ($status==="0"){$status="";}
		
		if (!isEmpty($job) && !isEmpty($status)) {
			$.post("<?= site_url() ?>setup/search_data1", {
				nama_jabatan: $('#nama_jabatan').val(),
				status_name: $('#status_name').val()
			},
			function(data) {
				$('#tablecontent').html(data);
			});			
		} else {
			$.post("<?= site_url() ?>setup/job_position", {}, function(data) {
				window.location = '<?php echo base_url();?>setup/job_position';
			});
		}
	}
	
	function search_data2() {
		$floor = $('#floor_name').val();
		$job   = $('#nama_jabatan2').val();
		$ruang = $('#ruang_name').val();
		$ruang_baru = $('#new_room').val();
		
		if ($floor==="0"){$floor="";}
		if ($job==="0"){$job="";}
		if ($ruang==="0"){$ruang="";}
		
		if (!isEmpty($floor) && !isEmpty($job) && isEmpty($ruang)) {
			$.post("<?= site_url() ?>setup/search_data2", {
				floor_name: $('#floor_name').val(), 
				nama_jabatan2: $('#nama_jabatan2').val(),
				ruang_name: "", 
				new_room: ""
			},
			function(data) {
				$('#tablecontent2').html(data);
				return false;
			});
		} 
		else 
		if (!isEmpty($floor) && !isEmpty($job) && !isEmpty($ruang)) {
			$.post("<?= site_url() ?>setup/search_data2", {
				floor_name: $('#floor_name').val(), 
				nama_jabatan2: $('#nama_jabatan2').val(),
				ruang_name: $('#ruang_name').val(), 
				new_room: $('#new_room').val()  				
			},
			function(data) {
				$('#tablecontent2').html(data);
				return false;
			});
		
		} else {
			$.post("<?= site_url() ?>setup/job_position", {}, function(data) {
				window.location = '<?php echo base_url();?>setup/job_position';
			});
		}			
	}
	
	function isEmpty(str){
		if(!str || 0 === str.length){
			return true;
		} else {return false; }
	}

	function add_data1() {
		$job   = $('#nama_jabatan').val();
		$status = $('#status_name').val();
	
		if ($job==="0"){$job="";}
		if ($status==="0"){$status="";}
		
		if ($job===""){alert('Job Position kosong!'); return false;}
		if ($status===""){alert('Status kosong!'); return false;}
		
		$work = $('#work_awal1').val();
		$stat = $('#status_awal1').val();
		
		if ($work==="0"){$work="";}
		if ($stat==="0"){$stat="";}
		
		if ($work===""){alert('Work Facility Name kosong!'); return false;} 
		if ($stat===""){alert('Work Facility Status kosong!'); return false;}
		
		if (!isEmpty($work) && !isEmpty($stat)) {
			$.post("<?= site_url() ?>setup/add_data1", {
				nama_jabatan: $('#nama_jabatan').val(),
				status_name: $('#status_name').val(),
				work_awal: $('#work_awal1').val(),
				status_awal: $('#status_awal1').val()
			},
			function(data) {
				$('#tablecontent').html(data);
			});			
		}
	}
	
	function add_data2() {
		$job   = $('#nama_jabatan').val();
		$status = $('#status_name').val();
	
		if ($job==="0"){$job="";}
		if ($status==="0"){$status="";}
		
		if ($job===""){alert('Job Position kosong!'); return false;}
		if ($status===""){alert('Status kosong!'); return false;}
		
		$work = $('#work2_awal').val();
		$stat = $('#status2_awal').val();
		
		if ($work==="0"){$work="";}
		if ($stat==="0"){$stat="";}
		
		if ($work===""){alert('Room Facility Name kosong!'); return false;} 
		if ($stat===""){alert('Room Facility Status kosong!'); return false;}
		
		if (!isEmpty($work) && !isEmpty($stat)) {
			$.post("<?= site_url() ?>setup/add_data2", {
				nama_jabatan: $('#nama_jabatan').val(),
				status_name: $('#status_name').val(),
				work2_awal: $('#work2_awal').val(),
				status2_awal: $('#status2_awal').val()
			},
			function(data) {
				$('#tablecontent').html(data);
			});			
		}
	}
	
	function add_data3() {
		$floor   	= $('#floor_name').val();
		$job   		= $('#nama_jabatan2').val();
		$ruang_name = $('#ruang_name').val();
		$new_room   = $('#new_room').val();
		
		$type_save=1;
		
		if (!isEmpty($ruang_name)) { $type_save=2; } 
	
		if ($floor==="0"){$floor="";}
		if ($job==="0"){$job="";}
		
		if ($floor===""){alert('Floor kosong!'); return false;}
		if ($job===""){alert('Job Position kosong!'); return false;}
		
		if (isEmpty($ruang_name)) { 
			if ($new_room===""){alert('New Name kosong!'); return false;}
		} else {
			$new_room   = $('#ruang_name').val();
			$type_save=2;
		}
		
		$work = $('#work_awal3').val();
		$stat = $('#status_awal3').val();
		
		if ($work==="0"){$work="";}
		if ($stat==="0"){$stat="";}
		
		if ($work===""){alert('All Facility Name kosong!'); return false;} 
		if ($stat===""){alert('All Facility Status kosong!'); return false;}
		
		if (!isEmpty($work) && !isEmpty($stat)) {
			$.post("<?= site_url() ?>setup/add_data3", {
				floor_name: $('#floor_name').val(),
				nama_jabatan2: $('#nama_jabatan2').val(),
				new_room: $new_room,
				work_awal3: $('#work_awal3').val(),
				status_awal3: $('#status_awal3').val(), 
				type_save: $type_save
			},
			function(data) {
				$('#tablecontent2').html(data);
			});			
		}
	}
	
	function delete_data1(ri_name) {
		if (confirm("Apakah Anda Yakin Ingin Delete Facility '"+ ri_name +"' ?")){
			$.post("<?= site_url() ?>setup/delete_data1", {
				ri_name: ri_name,
				ri_jabatan_name: $('#nama_jabatan').val(),
				ri_jabatan_status: $('#status_name').val()
			},
			function(data) {
				//window.location = '<?php echo base_url();?>setup/job_search_view';
				$('#tablecontent').html(data);
			});
		}
	}
	
	function delete_data2(ri_name) {
		if (confirm("Apakah Anda Yakin Ingin Delete Facility '"+ ri_name +"' ?")){
			$.post("<?= site_url() ?>setup/delete_data2", {
				rui_name: ri_name,
				rui_jabatan_name: $('#nama_jabatan').val(),
				rui_jabatan_status: $('#status_name').val()
			},
			function(data) {
				$('#tablecontent').html(data);
			});
		}
	}
	
	function delete_data3(rbl_id,ri_name) {
		if (confirm("Apakah Anda Yakin Ingin Delete Facility '"+ ri_name +"' ?")){  
			$.post("<?= site_url() ?>setup/delete_data3", {
				rbl_id			: rbl_id, 
				nama_jabatan2	: $('#nama_jabatan2').val(), 
				floor_name		: $('#floor_name').val(), 
				ruang_name		: $('#ruang_name').val(), 
				new_room		: $('#new_room').val() 
			},
			function(data) {
				$('#tablecontent2').html(data);
			});
		}
	}
	
	function edit_data1(ri_name,no_urut) {
		$job   = $('#nama_jabatan').val();
		$status = $('#status_name').val();
	
		if ($job==="0"){$job="";}
		if ($status==="0"){$status="";}
		
		if ($job===""){alert('Job Position kosong!'); return false;}
		if ($status===""){alert('Status kosong!'); return false;}
		
		$stat = $('#ri_status'+no_urut).val();
		
		if ($stat==="0"){$stat="";}
		if ($stat===""){alert('Work Facility Status kosong!'); return false;}
		
		if (!isEmpty($stat)) {
			
			$.post("<?= site_url() ?>setup/edit_data1", {
				ri_name: ri_name,
				ri_jabatan_name: $('#nama_jabatan').val(),
				ri_jabatan_status: $('#status_name').val(),
				ri_status: $('#ri_status'+no_urut).val()
			},
			function(data) {
				$('#tablecontent').html(data);
			});			
		}		
	}
	
	function edit_data2(ri_name,no_urut) {
		$job   = $('#nama_jabatan').val();
		$status = $('#status_name').val();
	
		if ($job==="0"){$job="";}
		if ($status==="0"){$status="";}
		
		if ($job===""){alert('Job Position kosong!'); return false;}
		if ($status===""){alert('Status kosong!'); return false;}
		
		$stat = $('#ri_status2'+no_urut).val();
		
		if ($stat==="0"){$stat="";}
		if ($stat===""){alert('Room Facility Status kosong!'); return false;}
		
		if (!isEmpty($stat)) {
			$.post("<?= site_url() ?>setup/edit_data2", {
				rui_name: ri_name,
				rui_jabatan_name: $('#nama_jabatan').val(),
				rui_jabatan_status: $('#status_name').val(),
				rui_status: $('#ri_status2'+no_urut).val()
			},
			function(data) {
				$('#tablecontent').html(data);
			});			
		}
	}
	
	function edit_data3(ri_id,ri_type,no_urut) {
		$stat = $('#ri_status'+no_urut).val();
		
		if ($stat==="0"){$stat="";}
		if ($stat===""){alert('All Facility Status kosong!'); return false;}
		
		if (!isEmpty($stat)) {
			
			$.post("<?= site_url() ?>setup/edit_data3", {
				rbl_job			: $('#nama_jabatan2').val(), 
				rbl_item_id		: ri_id, 
				rbl_item_tipe	: ri_type, 
				rbl_item_flag	: $('#ri_status'+no_urut).val(),  
				floor_name		: $('#floor_name').val(), 
				ruang_name		: $('#ruang_name').val(), 
				new_room		: $('#new_room').val() 
			},
			function(data) {
				$('#tablecontent2').html(data);
			});			
		}		
	}

</script>
